#include "friendapplylib.h"
#include <QDebug>
FriendApplyLib* FriendApplyLib::friendapply=nullptr;

FriendApplyLib *FriendApplyLib::getInstance()
{
    if(friendapply==nullptr)
    {
        friendapply=new FriendApplyLib();

    }
    return friendapply;
}

void FriendApplyLib::recvFrendApplyList(const QList<QPair<QPair<QString, QString>, uint8_t> > &result)
{
    applylist.clear();
    applylist=result;
    for(QPair<QPair<QString, QString>, uint8_t> i:applylist)
        ocset.insert(i.first.first);
    emit s_loadFriendApplyDone();
}

void FriendApplyLib::addApply(const QString &friendoc, const QString &friendname, const EnumLib::ApplyStatus status)
{
    if(ocset.contains(friendoc))return;
    applylist.push_back(QPair<QPair<QString,QString>,uint8_t>(QPair<QString,QString>(friendoc,friendname),static_cast<uint8_t>(status)));
    ocset.insert(friendoc);
    newapplycount++;
    emit s_haveNewApply(friendoc,friendname);
}

void FriendApplyLib::setApply(const QString& friendoc,const EnumLib::ApplyStatus status)
{
    for(auto i=applylist.begin();i<applylist.end();i++)
    {
        if(i->first.first==friendoc)
        {
            i->second=static_cast<uint8_t>(status);
            emit s_applyStatusChanged(friendoc,status);
            return;
        }
    }
}

bool FriendApplyLib::isEmpty()
{
    return applylist.isEmpty();
}

QList<QPair<QPair<QString, QString>, uint8_t> > FriendApplyLib::getList()
{
    return applylist;
}

void FriendApplyLib::clearLib()
{
    applylist.clear();
    ocset.clear();
}

bool FriendApplyLib::friendIsUnderrview(const QString &friendoc)
{
    for(QPair<QPair<QString,QString>,uint8_t> i: applylist)
    {
        if(i.first.first==friendoc)
            return static_cast<EnumLib::ApplyStatus>(i.second)==EnumLib::ApplyStatus::TARGETUNDERREVIEW;
    }
    return false;
}

void FriendApplyLib::resetNewCount()
{
    newapplycount=0;
}

int FriendApplyLib::getNewApplyCount()
{
    return newapplycount;
}

FriendApplyLib::FriendApplyLib()
{
    newapplycount=0;
}
